﻿using System;
using System.Collections.Generic;
using System.Text;
using FunctionalCLR;
using FunctionalCLR.Core;
using FunctionalCLR.Core.Function;

namespace FunctionalCLR.Shell.Function.IO {

    /// <summary>
    /// delete("c:\\hello.txt");
    /// </summary>
    public class DeleteNode : FuncNode {

        public DeleteNode()
            : base() {
            base.Value = "delete";
        }

        public override object Evaluate() {
            StringBuilder buff = new StringBuilder();

            foreach (Node child in Children) {
                if (!child.GetType().Equals(typeof(StringNode))) {
                    throw new Exception("Only strings are allowed.");
                }

                System.IO.File.Delete(((StringNode)child).Value);
            }

            return buff.ToString();
        }
    }
}
